package drive.Service.ServiceFormat;

import com.google.gson.Gson;
import drive.Mapper.FavoriteRecordMapper;
import drive.Model.FavoriteRecord;
import drive.Service.ServiceInterface.FavoriteRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FavoriteRecordServiceA implements FavoriteRecordService {
    @Autowired
    private FavoriteRecordMapper favoriteRecordMapper;

    private Gson gson = new Gson();

    @Override
    public String findAll() {
        List<FavoriteRecord> list = favoriteRecordMapper.findAll();
        return gson.toJson(list);
    }

    @Override
    public String findByFavoriteID(int favoriteID) {
        FavoriteRecord favoriteRecord = favoriteRecordMapper.findByFavoriteID(favoriteID);
        return gson.toJson(favoriteRecord);
    }

    @Override
    public String findByUserID(int userID) {
        List<FavoriteRecord> list = favoriteRecordMapper.findByUserID(userID);
        return gson.toJson(list);
    }

    @Override
    public String add(FavoriteRecord favoriteRecord) {
        int result = favoriteRecordMapper.add(favoriteRecord);
        return "收藏成功";
    }

    @Override
    public String update(FavoriteRecord favoriteRecord) {
        int result = favoriteRecordMapper.update(favoriteRecord);
        return "收藏信息已更改";
    }

    @Override
    public String delete(int favoriteID) {
        int result = favoriteRecordMapper.delete(favoriteID);
        return "取消收藏";
    }
}